//
//  MLButton.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/21.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "MLButton.h"

@implementation MLButton


///简单无背景版
+ (instancetype)buttonCreatedWithTitle:(NSString *)title
                                font:(CGFloat)fontSize
                          titleColor:(UIColor *)color
                            norImage:(NSString *)imageName
                           selectImg:(NSString *)selectImg{
    
    MLButton *btn = [[MLButton alloc] init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:selectImg] forState:UIControlStateSelected];
    
    
    btn.titleLabel.font = FONT(fontSize);
    
    
//    btn.backgroundColor = RED_COLOR;
    
    return btn;
}


///简单无背景版
- (instancetype)initCreatedWithTitle:(NSString *)title
                                font:(CGFloat)fontSize
                          titleColor:(UIColor *)color
                            norImage:(NSString *)imageName
                           selectImg:(NSString *)selectImg
                          clickBlock:(ClickBtnBlock)clickBlock{
    
    MLButton *btn = [[MLButton alloc] init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:selectImg] forState:UIControlStateSelected];
    
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    self.clickBtnBlock = clickBlock;
    
    btn.titleLabel.font = FONT(fontSize);
    
    return btn;
}

- (void)clickBtn:(UIButton *)btn{
    
    if(self.clickBtnBlock){
        
        self.clickBtnBlock();
    }
}

- (void)drawRect:(CGRect)rect{

    self.imageEdgeInsets = UIEdgeInsetsMake(0, -2, 0, 2);
}



@end
